package com.dayatang.android.config;


import android.content.Context;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.TextAppearanceSpan;
import android.view.Gravity;
import android.view.ViewGroup.LayoutParams;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class TableLayoutConfig {
	
	public static void AddTableRow(Context context, TableLayout tableLayout, TextAppearanceSpan textappearancespan, Object... objects) {

		TableRow row = new TableRow(context); 
		row.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
		
		for (int i = 0; i < 3; i++) {
			row.addView(newTextView(context, textappearancespan, objects[i]));
		}
		tableLayout.addView(row,new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));   
	}
	
	private static TextView newTextView(Context context, TextAppearanceSpan textappearancespan, Object text) {
		TextView t = new TextView(context);
		t.setGravity(Gravity.CENTER_HORIZONTAL);
		SpannableStringBuilder style=new SpannableStringBuilder((CharSequence) text);
		style.setSpan(textappearancespan,0,0,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		t.setText(style);
		return t;
	}
}	
